package com.gurun.camera.addDevice.model;

import com.danale.sdk.Danale;
import com.danale.sdk.platform.constant.device.SubscripType;
import com.danale.sdk.platform.entity.deviceinfo.DeviceAddedOnlineInfoV4;
import com.danale.sdk.platform.result.device.AddDeviceResult;
import com.danale.sdk.platform.result.deviceinfo.v4.DeviceAddedOnlineResultV4;
import com.danale.sdk.utils.MetaDataUtil;
import com.gurun.camera.account.activity.AccountUtil;

import java.util.Arrays;

import rx.Observable;
import rx.functions.Func1;

/**
 * Created by Administrator on 2016/12/22.
 */

public class AddDeviceModelImpl implements AddDeviceModel {
    @Override
    public Observable<DeviceAddedOnlineInfoV4> checkDeviceState(String deviceId) {
        return Danale.get().getPlatformDeviceInfoService().getDeviceAddedOnlineV4(1, Arrays.asList(new String[]{deviceId}),1,65535)
                .map(new Func1<DeviceAddedOnlineResultV4, DeviceAddedOnlineInfoV4>() {
                    @Override
                    public DeviceAddedOnlineInfoV4 call(DeviceAddedOnlineResultV4 deviceAddedOnlineResultV4) {
                        return deviceAddedOnlineResultV4.getDeviceAddedOnlineInfoList().get(0);
                    }
                });
    }

    @Override
    public Observable<AddDeviceResult> addDevice(String deviceId, String alias) {
        return Danale.get().getPlatformDeviceService().addDevice(1,deviceId,alias, MetaDataUtil.getCoreCode(AccountUtil.getInstance(null).getAppContext()),",", SubscripType.NOT_SUPPORT_SUBSCRIPTION);
    }
}
